import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Projects from '../views/Projects.vue'
import Resume from '../views/Resume.vue'
import CodeSnippets from '../views/CodeSnippets.vue'
import About from '../views/About.vue'
import Contact from '../views/Contact.vue'
import { siteConfig } from '../config/site'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    beforeEnter: (to, from, next) => {
      if (siteConfig) next()
    }
  },
  {
    path: '/about',
    name: 'About',
    component: About,
    beforeEnter: (to, from, next) => {
      if (siteConfig) next()
    }
  },
  {
    path: '/projects',
    name: 'Projects',
    component: Projects,
    beforeEnter: (to, from, next) => {
      if (siteConfig) next()
    }
  },
  {
    path: '/resume',
    name: 'Resume',
    component: Resume,
    beforeEnter: (to, from, next) => {
      if (siteConfig) next()
    }
  },
  {
    path: '/code-snippets',
    name: 'CodeSnippets',
    component: CodeSnippets,
    beforeEnter: (to, from, next) => {
      if (siteConfig) next()
    }
  },
  {
    path: '/contact',
    name: 'Contact',
    component: Contact,
    beforeEnter: (to, from, next) => {
      if (siteConfig) next()
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 确保配置数据已加载
  if (siteConfig) {
    next()
  } else {
    console.error('Config not loaded')
    next(false)
  }
})

export default router 